package com.yuqing.sentimentapp.yqlist.presenter.impl;

import com.linkface.baselibrary.http.BaseBean;
import com.yuqing.sentimentapp.base.BaseObserver;
import com.yuqing.sentimentapp.home.presenter.impl.IssuedPresenterImpl;
import com.yuqing.sentimentapp.module.ModuleManager;
import com.yuqing.sentimentapp.yqlist.activity.YuQingDetailActivity;
import com.yuqing.sentimentapp.yqlist.bean.YqDetailResultBean;
import com.yuqing.sentimentapp.yqlist.bean.YqReplyResultBean;
import com.yuqing.sentimentapp.yqlist.presenter.YqDetailPresenter;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class YqDetailPresenterImpl implements YqDetailPresenter {

    private YuQingDetailActivity yuQingDetailActivity;

    public YqDetailPresenterImpl(YuQingDetailActivity yuQingDetailActivity) {
        this.yuQingDetailActivity = yuQingDetailActivity;
    }

    @Override
    public void loadYqDetailData(String articleId, String deptCode) {
        ModuleManager.getInstance().loadYqDetailResult(yuQingDetailActivity, articleId, deptCode)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<YqDetailResultBean>() {
                    @Override
                    protected void hideDialog() {
                        yuQingDetailActivity.stopProgressDialog();
                    }

                    @Override
                    protected void showDialog() {
                        yuQingDetailActivity.startProgressDialog();
                    }

                    @Override
                    protected void onSuccess(YqDetailResultBean yqDetailResultBean) {
                        yuQingDetailActivity.onSuccess(yqDetailResultBean);
                    }

                    @Override
                    protected void onFailure(String message) {
                        yuQingDetailActivity.onFailure(message);
                    }
                });
    }

    @Override
    public void replyRequest(String replyId, String remark, int position) {
        ModuleManager.getInstance().replyRequest(yuQingDetailActivity, replyId, remark)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<YqReplyResultBean>() {
                    @Override
                    protected void hideDialog() {
                        yuQingDetailActivity.stopProgressDialog();
                    }

                    @Override
                    protected void showDialog() {
                        yuQingDetailActivity.startProgressDialog();
                    }

                    @Override
                    protected void onSuccess(YqReplyResultBean baseBean) {
                        yuQingDetailActivity.replySuccess(baseBean, position);
                    }

                    @Override
                    protected void onFailure(String message) {
                        yuQingDetailActivity.onFailure(message);
                    }
                });
    }
}
